<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增模版</title>
    <link rel="stylesheet" href="/static/lib/pear/css/pear.css?v=0.04"/>
    <link rel="stylesheet" href="/static/admin/style/admin.css?v=0.04"/>
</head>
<body>
<style>
    .layui-textarea {
        height: 10em;
    }

    .layui-tab .layui-table-cell {
        overflow: visible !important;
    }

    .layui-table-body, .layui-table-box {
        overflow: visible !important;
    }

    .layui-tab .layui-form-select dl {
        max-height: 190px;
    }

    .layui-table-body .layui-table-col-special:last-child {
        width: 100% !important;
        border-right: 1px solid #eee !important;
    }

    xm-select {
        min-height: 38px;
        line-height: 38px;
    }

    xm-select .xm-body .xm-option .xm-option-icon {
        font-size: 18px !important;
    }
</style>

<form class="layui-form" action="" lay-filter="create-template-form">

    <div class="mainBox">
        <div class="main-container mr-5">

            <div class="layui-form-item">
                <label class="layui-form-label required">模版名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" required lay-verify="required" placeholder="模版名"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">发件人</label>
                <div class="layui-input-block">
                    <input type="text" name="from" required lay-verify="required" placeholder="发件人"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">主题</label>
                <div class="layui-input-block">
                    <input type="text" name="subject" required lay-verify="required" placeholder="主题"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">邮件内容</label>
                <div class="layui-input-block">
                    <textarea name="content" placeholder="请输入内容" required lay-verify="required"
                              class="layui-textarea"></textarea>
                </div>
            </div>


        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                    lay-filter="save">
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-md">
                重置
            </button>
        </div>
    </div>
</form>

<script src="/static/lib/layui/layui.js?v=0.04"></script>
<script src="/static/lib/pear/pear.js?v=0.04"></script>
<script src="/static/admin/js/hui_admin.js?v=0.04"></script>

<script>

  const INSERT_API = "/app/email/email/insertTemplate";

  layui.use(["form", "popup"], function () {

    layui.$.ajax({
      url: "/app/email/email/get",
      success: function (res) {
        if (res.code === 0) {
          return layui.popup.failure(res.msg);
        }
        layui.form.val("create-template-form", {from: res.data.From});
      }
    });

    //提交事件
    layui.form.on("submit(save)", function () {
      let data = layui.form.val("create-template-form");
      layui.$.ajax({
        url: INSERT_API,
        type: "POST",
        dateType: "json",
        data: data,
        success: function (res) {
          if (res.code === 0) {
            return layui.popup.failure(res.msg);
          }
          return layui.popup.success("操作成功", function () {
            parent.refreshTable();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
          });
        }
      });
      return false;
    });
  });

</script>

</body>
</html>
